// pages/interface/equipmanage/equipmanage.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user_id: null,
    equipments: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var that = this;
      var username = app.globalData.username;
      // 根据username获取user_id
      wx.request({
        url: 'https://car.shiliangproject.cn/user/showuserid?username=' + username,
        data: { username: username },
        header: { "Content-Type": 'application/json' },
        method: "GET",
        success: function (res) {
          console.log(res['data']);
          // 赋值到当前页面data
          that.setData({
              user_id: res['data']
          });
        },
      });
      // 请求equipments接口并做数据筛选
      wx.request({
        url: 'https://car.shiliangproject.cn/equipment/showallequip',
        data: { },
        header: { "Content-Type": 'application/json' },
        method: "GET",
        success: function (res) {
            console.log(res['data']);
            // 筛选车位信息
            var equips = [];
            for (var i=0;i<res['data'].length;i++) {
              if (res['data'][i]['userId'] == that.data.user_id) {
                equips[i] = res['data'][i];
              }
            }
            that.setData({
              equipments: equips
            });
            console.log(that.data.equipments);            
        },
      });


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})